home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Alpha Blending Lines and Fills / Using Compositing Mode to Control Alpha Blending / GDITEST4.dpr
Encoding:
Text File  |  2003-10-15  |  3.8 KB  |  131 lines

  1. program GDITEST4;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   bitmapGraphics, Graphics : TGPGraphics;
  13.   Bitmap: TGPBitmap;
  14.   redBrush, greenBrush, brush: TGPSolidBrush;
  15. begin
  16.  
  17.   // Create a blank bitmap.
  18.   Bitmap := TGPBitmap.Create(180, 100, PixelFormat32bppARGB);
  19.  
  20.   // Create a Graphics object that we can use to draw on the bitmap.
  21.   bitmapGraphics := TGPGraphics.Create(bitmap);
  22.  
  23.   // Create a red brush and a green brush, each with an alpha value of 160.
  24.   redBrush := TGPSolidBrush.Create(MakeColor(210, 255, 0, 0));
  25.   greenBrush := TGPSolidBrush.Create(MakeColor(210, 0, 255, 0));
  26.  
  27.   // Set the compositing mode so that when we draw overlapping ellipses,
  28.   // the colors of the ellipses are not blended.
  29.   bitmapGraphics.SetCompositingMode(CompositingModeSourceCopy);
  30.  
  31.   // Fill an ellipse using a red brush that has an alpha value of 160.
  32.   bitmapGraphics.FillEllipse(redBrush, 0, 0, 150, 70);
  33.  
  34.   // Fill a second ellipse using green brush that has an alpha value of 160.
  35.   // The green ellipse overlaps the red ellipse, but the green is not
  36.   // blended with the red.
  37.   bitmapGraphics.FillEllipse(greenBrush, 30, 30, 150, 70);
  38.  
  39.   Graphics := TGPGraphics.Create(DC);
  40.  
  41.   Graphics.SetCompositingQuality(CompositingQualityGammaCorrected);
  42.  
  43.   // Draw a multicolored background.
  44.   brush := TGPSolidBrush.Create(aclAqua);
  45.   Graphics.FillRectangle(brush, 200, 0, 60, 100);
  46.   brush.SetColor(aclYellow);
  47.   Graphics.FillRectangle(brush, 260, 0, 60, 100);
  48.   brush.SetColor(aclFuchsia);
  49.   Graphics.FillRectangle(brush, 320, 0, 60, 100);
  50.  
  51.   // Display the bitmap on a white background.
  52.   Graphics.DrawImage(bitmap, 0, 0);
  53.  
  54.   // Display the bitmap on a multicolored background.
  55.   Graphics.DrawImage(bitmap, 200, 0);
  56.  
  57.   bitmapGraphics.Free;
  58.   Bitmap.Free;
  59.   redBrush.Free;
  60.   greenBrush.Free;
  61.   brush.Free;
  62.   graphics.Free;
  63. end;
  64.  
  65.  
  66. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  67. var
  68.   Handle: HDC;
  69.   ps: PAINTSTRUCT;
  70. begin
  71.   case message of
  72.     WM_PAINT:
  73.       begin
  74.         Handle := BeginPaint(Wnd, ps);
  75.         OnPaint(Handle);
  76.         EndPaint(Wnd, ps);
  77.         result := 0;
  78.       end;
  79.  
  80.     WM_DESTROY:
  81.       begin
  82.         PostQuitMessage(0);
  83.         result := 0;
  84.       end;
  85.  
  86.    else
  87.       result := DefWindowProc(Wnd, message, wParam, lParam);
  88.    end;
  89. end;
  90.  
  91. var
  92.   hWnd     : THandle;
  93.   Msg      : TMsg;
  94.   wndClass : TWndClass;
  95. begin
  96.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  97.    wndClass.lpfnWndProc    := @WndProc;
  98.    wndClass.cbClsExtra     := 0;
  99.    wndClass.cbWndExtra     := 0;
  100.    wndClass.hInstance      := hInstance;
  101.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  102.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  103.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  104.    wndClass.lpszMenuName   := nil;
  105.    wndClass.lpszClassName  := 'GettingStarted';
  106.  
  107.    RegisterClass(wndClass);
  108.  
  109.    hWnd := CreateWindow(
  110.       'GettingStarted',       // window class name
  111.       'Using Compositing Mode to Control Alpha Blending',       // window caption
  112.       WS_OVERLAPPEDWINDOW,    // window style
  113.       Integer(CW_USEDEFAULT), // initial x position
  114.       Integer(CW_USEDEFAULT), // initial y position
  115.       Integer(CW_USEDEFAULT), // initial x size
  116.       Integer(CW_USEDEFAULT), // initial y size
  117.       0,                      // parent window handle
  118.       0,                      // window menu handle
  119.       hInstance,              // program instance handle
  120.       nil);                   // creation parameters
  121.  
  122.    ShowWindow(hWnd, SW_SHOW);
  123.    UpdateWindow(hWnd);
  124.  
  125.    while(GetMessage(msg, 0, 0, 0)) do
  126.    begin
  127.       TranslateMessage(msg);
  128.       DispatchMessage(msg);
  129.    end;
  130. end.
  131.